
package com.fdl.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fdl.common.exception.security.LoginTimeOutException;
import com.fdl.service.security.impl.SecurityUtils;

/**
 * 登陆超时过虑 
 * @project: cp-website
 * @Date:2010-12-22
 * @version  1.0
 * @Company: 33e9
 * @author zhangYong.huang
 */
public class LoginTimeoutFilter  implements Filter{

	private String loginURL;
	
	public void destroy() {};

	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
			FilterChain chain) throws IOException, ServletException {
		HttpServletResponse response=(HttpServletResponse)servletResponse;
		HttpServletRequest request=(HttpServletRequest)servletRequest;
		try {
			SecurityUtils.getCurrentUser();
			chain.doFilter(request, response);
			return;
		} catch (LoginTimeOutException e) {
			response.sendRedirect(request.getContextPath() + loginURL);
			return;
		}
		
	}

	public void init(FilterConfig config) throws ServletException {
		loginURL = config.getInitParameter("loginURL");
	}

}

